package com.jn.erp.wechat.mp.init;


import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
//import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
//import me.chanjar.weixin.common.error.WxErrorException;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;

/**
 * <pre>
 *
 * </pre>
 *
 * @author sunjiyong
 * @since 2024/11/25 16:09
 */
@Component
public class WxMpInit {

    private final WxMpService wxMpService;

    @Autowired
    public WxMpInit(@Qualifier("wxMpJnService") WxMpService wxMpService){
        this.wxMpService = wxMpService;
    }


    /**
     * 项目启动时，初始化公众号菜单
     */
    @PostConstruct
    public  void init()   {
        System.out.println("开始执行菜单初始化操作");
//        Map<String, List<Map>> params =new HashMap<>();
//        List<Map> menus=new ArrayList<>();
//
//        //关联家校通
//        Map<String,Object> m1=new HashMap<>();
//        List<Map> msub1=new ArrayList<>();
//        //家长端
//        Map<String,Object> m11=new HashMap<>();
//        m11.put("name", "家长通");m11.put("appid", "wxb593ce1ec505b074");m11.put("type", "miniprogram");
//        m11.put("url", "http://mp.weixin.qq.com");    m11.put("pagepath", "pages/tabbar/growup/growup");
//        msub1.add(m11);
//        //教师端
//        Map<String,Object> m12=new HashMap<>();
//        m12.put("name", "教师通");m12.put("appid", "wx00f3462c9e7d0454");m12.put("type", "miniprogram");
//        m12.put("url", "http://mp.weixin.qq.com");    m12.put("pagepath", "pages/tabbar/work/index");
//        msub1.add(m12);
//
//        m1.put("name", "家校通");
//        m1.put("sub_button", msub1);
//
//        menus.add(m1);
//
//
//
//        //绑定手机号
//        Map<String,String> m2=new HashMap<>();
//        m2.put("type", "click"); m2.put("name", "开通状态");m2.put("key", "isBind");
//        menus.add(m2);
//////
//////        //跳转链接
//////        Map<String,String> m3=new HashMap<>();
//////        m3.put("type", "view"); m3.put("name", "跳转页面");m3.put("url", "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx9504fed6da328451&redirect_uri=https%3a%2f%2fjnzsrd.top%2fregister&response_type=code&scope=snsapi_base&state=ACE#wechat_redirect");
//////        menus.add(m3);
//
//        params.put("button",menus);
//        try {
//            wxMpService.post("https://api.weixin.qq.com/cgi-bin/menu/create", WxMaGsonBuilder.create().toJson(params));
//            System.out.println("运行操作已完成！");
//        }catch (WxErrorException e){
//            System.out.println("create");
//            System.out.println(e.getError());
//        }
    }
}
